Method: String#<=>
- Defined in:
- string.c
#<=>(other_string) ⇒ -1, ...
Compares self and other_string, returning:
-
-1 if
other_stringis larger. -
0 if the two are equal.
-
1 if
other_stringis smaller. -
nilif the two are incomparable.
Examples:
'foo' <=> 'foo' # => 0
'foo' <=> 'food' # => -1
'food' <=> 'foo' # => 1
'FOO' <=> 'foo' # => -1
'foo' <=> 'FOO' # => 1
'foo' <=> 1 # => nil
4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 |
# File 'string.c', line 4211 static VALUE rb_str_cmp_m(VALUE str1, VALUE str2) { int result; VALUE s = rb_check_string_type(str2); if (NIL_P(s)) { return rb_invcmp(str1, str2); } result = rb_str_cmp(str1, s); return INT2FIX(result); } |